package com.dream.keigezhushou.Activity.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.bean.ComboInfo;
import com.dream.keigezhushou.Activity.wigdt.MyGridView;
import com.dream.keigezhushou.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class YudingbaoxiangActivity extends BaseActivity {


    @BindView(R.id.back)
    ImageView mBack;
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.nametitle)
    TextView mNametitle;
    @BindView(R.id.typektv)
    TextView mTypektv;
    @BindView(R.id.totime)
    TextView mTotime;
    @BindView(R.id.gridView)
    MyGridView mGridView;
    @BindView(R.id.combolist)
    ListView mCombolist;
    @BindView(R.id.tv_phone)
    TextView mTvPhone;
    @BindView(R.id.et_phone)
    EditText mEtPhone;
    @BindView(R.id.fh)
    TextView mFh;
    @BindView(R.id.activity_yudingbaoxiang)
    LinearLayout mActivityYudingbaoxiang;
    @BindView(R.id.gopay)
    TextView mGopay;
    private String[] iconName = {"13:30", "13:30", "13:30", "13:30", "13:30", "13:30", "13:30", "13:30", "13:30", "13:30"};
    private ArrayList<ComboInfo> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yudingbaoxiang);
        ButterKnife.bind(this);

        mGridView.setAdapter(new MyGridViewAdapter());

        initdata();
        mCombolist.setAdapter(new Madapter());

    }

    private void initdata() {
        for (int i = 0; i < 5; i++) {
            ComboInfo info = new ComboInfo();
            info.setChoose(true);
            info.setComboname("6小时欢唱+酒水套餐E");
            info.setDes("雪花啤酒/昆仑山矿泉水4瓶＋爆米花＋小吃2份");
            info.setPrice("68");
            list.add(info);
        }
    }

    @OnClick({R.id.back, R.id.nametitle, R.id.typektv, R.id.gopay})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.nametitle:
                break;
            case R.id.typektv:
                break;
            case R.id.gopay:
                Intent intent = new Intent(this, PayFromActivity.class);

                startActivity(intent);
                break;
        }
    }

    @OnClick(R.id.back)
    public void onClick() {
    }


    class MyGridViewAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return iconName.length;
        }

        @Override
        public Object getItem(int position) {
            return iconName[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                convertView = UiUtils.inflateView(R.layout.gridview_item);
                holder = new ViewHolder();
                holder.tv = (TextView) convertView.findViewById(R.id.tv);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            Object item = getItem(position);
            holder.tv.setText(item.toString());
            return convertView;
        }
    }

    static class ViewHolder {
        TextView tv;
    }

    class Madapter extends BaseAdapter {
        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public ComboInfo getItem(int position) {
            return list.get(position);

        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ComboViewHolder holder = null;
            if (convertView == null) {
                convertView = UiUtils.inflateView(R.layout.item_combo);
                holder = new ComboViewHolder();
                holder.iv = (ImageView) convertView.findViewById(R.id.choose);
                holder.des = (TextView) convertView.findViewById(R.id.combodetail);
                holder.comboname = (TextView) convertView.findViewById(R.id.comboname);
                holder.price = (TextView) convertView.findViewById(R.id.price);

                convertView.setTag(holder);

            } else {
                holder = (ComboViewHolder) convertView.getTag();
            }
            ComboInfo info = getItem(position);

            if (info.isChoose()) {
                holder.iv.setImageDrawable(getResources().getDrawable(R.mipmap.choose_select));
            } else {
                holder.iv.setImageDrawable(getResources().getDrawable(R.mipmap.choose));
            }

            holder.des.setText(info.getDes());
            holder.comboname.setText(info.getComboname());
            holder.price.setText("¥" + info.getPrice());

            return convertView;
        }
    }

    static class ComboViewHolder {
        private TextView comboname;
        private TextView des;
        private TextView price;
        private ImageView iv;

    }
}
